<?php
/**
 * Formulier voor Registereren
 *
 * Zie ook:
 * http://framework.zend.com/manual/en/zend.form.html
 *
 * @author     Olivier Parent
 * @copyright  Copyright (c) 2011 Artevelde University College Ghent
 */
class Application_Form_Registration extends Zend_Form
{

    public function init()
    {
        $translate = Zend_Registry::get('Zend_Translate');

        // Veld 'Voornaam'
        $this->addElement('text', 'givenname', array(
            'label'      => $translate->_('form_input_label_givenname'),
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alpha',
                // (validator_naam, stop_valideren_bij_fout, constructor_opties)
                array('StringLength', false, array(1, 45)),
            ),
        ));

        // Veld 'Familienaam'
        $this->addElement('text', 'familyname', array(
            'label'      => $translate->_('form_input_label_familyname'),
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alpha',
                // (validator_naam, stop_valideren_bij_fout, constructor_opties)
                array('StringLength', false, array(1, 45)),
            ),
        ));

        // Veld 'E-mailadres'
        $this->addElement('text', 'email', array(
            'label'      => $translate->_('form_input_label_email'),
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                // (validator_naam, stop_valideren_bij_fout)
                array('EmailAddress', true),
             ),
        ));
        // voeg gepersonaliseerde validatorklasse toe
        #$this->getElement('email')->addValidator(new Ahs_Validate_EmailInUse());

        // Veld 'Wachtwoord'
        $this->addElement('password', 'password', array(
            'label'      => $translate->_('form_input_label_password'),
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alnum',
                // (validator_naam, stop_valideren_bij_fout, constructor_opties)
                array('StringLength', false, array(8, 45)),
            ),
        ));

        // Veld 'Wachtwoord (herhaal)'
        $this->addElement('password', 'passwordRepeat', array(
            'label'      => $translate->_('form_input_label_passwordRepeat'),
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alnum',
                // (validator_naam, stop_valideren_bij_fout, constructor_opties)
                array('StringLength', false, array(8, 45)),
                array('Identical', true, array('password')),
            ),
        ));
        
        // Veld 'Geboortedatum'
        $this->addElement('text', 'dob', array(
            'label'      => $translate->_('form_input_label_dob'),
            'required'   => false,
            'filters'    => array('StringTrim'),
            'validators' => array(
                // (validator_naam, stop_valideren_bij_fout, constructor_opties)
                array('Regex', true, array('pattern' => '/^\d{4}-\d{2}-\d{2}$/')),
                array('Date', false, array('format' => 'YMd')),
             ),
        ));

        // Veld 'Geslacht'
        $this->addElement('radio', 'gender', array(
            'label'        => $translate->_('form_input_label_gender'),
            'required'     => false,
            'multioptions' => array(
                'male'   => $translate->_('form_input_label_gender_male'),
                'female' => $translate->_('form_input_label_gender_female'),
             ),
            //'value' => 'female',
        ));
        
        // Knop 'Versturen'
        $this->addElement('submit', 'send', array(
            'label'      => $translate->_('form_button_label_send'),
        ));

        // CSRF-preventie (Cross-Site Request Forgery)
        $this->addElement('hash', 'no_csrf_registration', array(
            'salt' => 'unique',
        ));

    }

}
